package com.zang.server.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zang.server.mapper.OperationLogMapper;
import com.zang.server.mapper.OplogMapper;
import com.zang.server.pojo.*;
import com.zang.server.service.impl.OperationLogServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zang
 * @since 2021-12-28
 */
@Api(tags = "日志管理")
@RestController
@RequestMapping("/system/log")
public class OplogController {
    @Autowired
    private OperationLogServiceImpl operationLogService;
    @ApiOperation("获取所有日志信息")
    @GetMapping("/")
    public RespPageBean getLogList(@RequestParam(defaultValue = "1") Integer currentPage,
                                   @RequestParam(defaultValue = "10") Integer size,
                                   OperationLog operationLog){
        return operationLogService.getPage(currentPage,size,operationLog);
    }
    @ApiOperation("根据id查询id")
    @DeleteMapping("/{id}")
    public RespBean deleteOneLog(@PathVariable("id") Integer id){
        boolean b = operationLogService.removeById(id);
        if (b){
            return RespBean.success("删除日志成功");
        }
        return RespBean.error("删除日志失败");
    }
    //redis 的缺点和优点
    @ApiOperation("批量删除日志信息")
    @DeleteMapping("/")
    public RespBean deleteList(Integer[] ints){
        boolean b = operationLogService.removeByIds(Arrays.asList(ints));

        if (b){
            return RespBean.success("批量删除成功");
        }
        return RespBean.error("批量删除失败");
    }
    @ApiOperation("模糊查询日志")
    @GetMapping("/{information}")
    public RespBean getLike(@PathVariable("information") String information){
        List<OperationLog> list = operationLogService.list(new QueryWrapper<OperationLog>().like("opt_module", information));
        if (list==null){
            return RespBean.error("没有找到对应的日志哦");
        }
        return RespBean.success("成功找到数据",list);
    }



}
